# Process this file with automake to produce a Makefile.in

# Project homepage: http://tovid.wikia.com
#
#
# Copyright (C) 2005 tovid <http://tovid.wikia.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Or see:
#
#           http://www.gnu.org/licenses/gpl.txt

# List the source files for each shell script
sh_bin = \
	src/idvid \
	src/makedvd \
	src/makemenu \
	src/makevcd \
	src/makexml \
	src/postproc \
	src/todisc \
	src/todisc-fade-routine \
	src/makempg \
	src/tovid-batch \
	src/tovid-init \
	src/tovid-interactive \
	src/make_titlesets
# Removed from sh_bin
#src/tovid-test

# List the source files for each python script
py_bin = \
	src/tovid \
	src/todiscgui \
	src/tovid-stats
# Removed from py_bin
#src/genvid
#src/pyidvid
#src/pytovid
#src/pymakemenu
#src/pymakexml

# Override the default bindir, so the tovid executables are
# installed to e.g. /usr/share/tovid/bin
# FIXME: This is probably not the correct way to do it
#bindir = $(datadir)/tovid/bin
bindir = $(libdir)/tovid

# Specify the scripts to make and install.
bin_SCRIPTS = \
	$(sh_bin) \
	$(py_bin)

# The manpages
man_dir = docs/man
man_src_dir = docs/src/en
man_MANS = \
	$(man_dir)/tovid.1
src_MANS = \
	$(man_src_dir)/tovid.t2t

# Make the manpages for svn users (tarball users' man pages made in dist-hook)
#   This is a static pattern rule as seen on (TV!)
#   http://www.gnu.org/software/make/manual/make.html#Static-Pattern
$(man_MANS): $(man_dir)/%.1: $(man_src_dir)/%.t2t
	txt2tags -t man -i "$<" -o "$@"

# Shared data: icons and .desktop files
# Icons -- freedesktop.org scheme
icon_top_dir = icons/hicolor
icon_svg_dir = scalable/apps
icon_128_dir = 128x128/apps
icon_64_dir = 64x64/apps
icon_48_dir = 48x48/apps
icon_32_dir = 32x32/apps

# Install directories, $(datadir) == $(prefix)/share
icon_base_dir = $(datadir)/$(icon_top_dir)
icon128dir = $(icon_base_dir)/$(icon_128_dir)
icon64dir = $(icon_base_dir)/$(icon_64_dir)
icon48dir = $(icon_base_dir)/$(icon_48_dir)
icon32dir = $(icon_base_dir)/$(icon_32_dir)
iconSVGdir = $(icon_base_dir)/$(icon_svg_dir)
appdir = $(datadir)/applications

# Distribute the data
dist_icon128_DATA = $(icon_top_dir)/$(icon_128_dir)/tovid.png
dist_icon64_DATA = $(icon_top_dir)/$(icon_64_dir)/tovid.png
dist_icon48_DATA = $(icon_top_dir)/$(icon_48_dir)/tovid.png
dist_icon32_DATA = $(icon_top_dir)/$(icon_32_dir)/tovid.png
dist_iconSVG_DATA = $(icon_top_dir)/$(icon_svg_dir)/cd.svg \
	$(icon_top_dir)/$(icon_svg_dir)/disc.svg \
	$(icon_top_dir)/$(icon_svg_dir)/tovid.svg
dist_app_DATA = \
	tovidgui.desktop


# Distribute the scripts and manpage source files
# manpages are made and packaged in the dist-hook for tarball users which
# prevents them from having to install txt2tags to make the mans, thus
# they aren't listed here.
#   NOTE: this is a bit of a hack. When 'make dist' is called, make puts
#   the manpage source in the pre-tarball directory. After everything is
#   finished, the dist-hook comes into play and fresh man pages are made.
#   We're taking advangtage of this order (make will _always_ do the hook
#   after the action, that's why it's a 'hook'!) to ensure that the derived
#   .1 manpages are newer than the .t2t source files. If the man sources are
#   removed from the distributed tarball, make will try to remake the .1 pages
#   since it always executes rules for targets without prerequisites,
#   thinking that it's a rule like clean: .
EXTRA_DIST = \
	$(bin_SCRIPTS) \
	$(src_MANS) \
	SENSE

# Shared python libraries: libtovid and the gui
# See lengthy comments in configure.ac
# $(pythondir) is the "The directory name for the site-packages subdirectory
# of the standard Python install tree." and is generated by configure.ac's
# AM_PATH_PYTHON. Typically, this points to
# $(prefix)/lib/pythonM.m/site-packages
# $(prefix) generally defaults to /usr/local for ./configure
# and "make install"

# Specifying a module to install: use 'python'
# 'python' works as a prefix of sorts: if you have files that need to be
# installed into separate directories, use another python variable pair.
# Say you want to install a python module in $(pythondir)/FOO , then
# you'll need to define a pair of variables:
#   (1) pythonFOO_PYTHON   which takes the python source files
#   (2) pythonFOOdir       which points to where the module should be installed
#                          (CAPS are not required, but helps readability)
pythonLIBTOVID_PYTHON 	= libtovid/*.py
pythonLIBTOVIDdir 		= $(pythondir)/libtovid
# Submodules
pythonGUIS_PYTHON 		= libtovid/guis/*.py
pythonGUISdir 			= $(pythondir)/libtovid/guis
pythonBACKEND_PYTHON 	= libtovid/backend/*.py
pythonBACKENDdir 		= $(pythondir)/libtovid/backend
pythonRENDER_PYTHON 	= libtovid/render/*.py
pythonRENDERdir 		= $(pythondir)/libtovid/render
pythonTEMPLATE_PYTHON 	= libtovid/template/*.py
pythonTEMPLATEdir 		= $(pythondir)/libtovid/template
pythonMETAGUI_PYTHON 	= libtovid/metagui/*.py
pythonMETAGUIdir 		= $(pythondir)/libtovid/metagui
pythonUTIL_PYTHON 		= libtovid/util/*.py
pythonUTILdir 			= $(pythondir)/libtovid/util

# src/tovid-init not needed b/c ./configure derives it from src/tovid-init.in
# make the output directory for the man pages, since t2t won't
dist-hook:
	rm -rvf $(top_distdir)/src/tovid-init
	mkdir $(top_distdir)/docs/man

# Hook to create a symbolic link for the main 'tovid' script
# FIXME: $(LN_S) is supposed to work since AC_PROG_LN_S is in configure.ac,
# but it doesn't for whatever reason (evaluates to empty string).
# For now, using explicit `ln -s`
install-exec-hook:
	rm -fv "$(prefix)/bin/tovid"
	ln -s "$(DESTDIR)$(bindir)/tovid" "$(prefix)/bin/tovid"

# After uninstalling tovid, remove the python module directories
uninstall-hook:
	rmdir $(pythonGUISdir)
	rmdir $(pythonBACKENDdir)
	rmdir $(pythonRENDERdir)
	rmdir $(pythonTEMPLATEdir)
	rmdir $(pythonMETAGUIdir)
	rmdir $(pythonUTILdir)
	rmdir $(pythonLIBTOVIDdir)
	rm $(prefix)/bin/tovid

# A little fun :-)
sense:
	fold -w 78 -s SENSE | less

# Allow only the bash scripts to be installed/uninstalled
# These were copied and modified from the Makefile after ./configure was
# run. A little quantum leaping :-)
install-bash: $(sh_bin)
	@$(NORMAL_INSTALL)
	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
	@list='$(sh_bin)'; for p in $$list; do \
	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
	  if test -f $$d$$p; then \
	    f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
	    echo " $(binSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(bindir)/$$f'"; \
	    $(binSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(bindir)/$$f"; \
	  else :; fi; \
	done

uninstall-bash:
	@$(NORMAL_UNINSTALL)
	@list='$(sh_bin)'; for p in $$list; do \
	  f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
	  echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
	  rm -f "$(DESTDIR)$(bindir)/$$f"; \
	done

